package items;

import elements.Element;
import elements.Robot;
import be.kuleuven.cs.som.annotate.Basic;
import be.kuleuven.cs.som.annotate.Immutable;
/**
 * @invar	| canHaveAsWeight(this.getWeight())
 * 
 * @version	3.0
 * @author 	Lies Tambeur 	r0264469	2Bcwsbbh
 * @author	Eline Vanrykel	r0264543	2Bcwselt
 *
 */
public abstract class Item extends Element{
	
	private int weight;
	
	/**
	 * @invar	| MAX_WEIGHT > 0
	 */
	private static final int MAX_WEIGHT = Integer.MAX_VALUE;
	
	/**
	 * @return | result == Battery.MAX_WEIGHT
	 */
	@Basic @Immutable
	public static final int getMaxWeight(){
		return MAX_WEIGHT;
	}
	
	public abstract void used(Robot robot);
	
	/**
	 * @param 	weight
	 * @effect	| setWeight(weight)
	 */
	protected Item(int weight){
		this.setWeight(weight);
	}
	
	/**
	 * @param  	weight
	 * @return	| result ==  (weight > 0) && (weight < Item.getMaxWeight())
	 */
	public boolean canHaveAsWeight(double weight) {
		return (weight > 0) && (weight < Item.getMaxWeight());
	}
	
	/**
	 * @return	| result == this.weight
	 */
	@Basic
	public int getWeight() {
		return weight; 
	}
	
	/**
	 * @param 	weight
	 * @post	| (canHaveAsWeight(Math.abs(weight))) == (new.getWeight() == Math.abs(weight))
	 * @post	| (!canHaveAsWeight(Math.abs(weight))) == (new.getWeight() == Item.getMaxWeight())
	 */
	private void setWeight(int weight){
		if(!canHaveAsWeight(Math.abs(weight))){
			this.weight = Item.getMaxWeight();
		}
		else{
			this.weight = Math.abs(weight);
		}
	}

	
}
